<template>
  <div id="app">
    <button v-on:click="getUserInfoClick">获取用户信息</button>
    <button v-on:click="appLinkClick">内链跳转</button>
    <button v-on:click="isLoginClick">是否登录</button>
    <button v-on:click="dialogClick">dialog测试</button>
    <button v-on:click="loginAppClick">登录app</button>
    <div>{{ message }}</div>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      message: "Hello Vue!",
    };
  },
  components: {},
  mounted() {
    // native调用js 提前注入方法
    this.$jsbrige.registerHandler("isLoginClick", (datas) => {
      alert(datas);
      this.$jsbrige.callNative("nativeToast", datas, function () {});
    });
  },
  methods: {
    getUserInfoClick: function () {
      var that = this;
      that.$jsbrige.callNative("fetchUserInfo", null, function (data) {
        alert(data);
        that.message = data;
        that.$jsbrige.callNative("nativeToast", data, function (data1) {
          alert(data1);
        });
      });
    },
    appLinkClick: function () {
      this.$jsbrige.callNative(
        "appLinkAction",
        { appLink: "v2gogo://openrouter/accountAndSafePage" },
        function (data) {
          alert(data);
        }
      );
    },
    isLoginClick: function () {
      var that = this;
      this.$jsbrige.callNative("isLogin", {}, function (data) {
        that.$jsbrige.callNative("nativeToast", data, function () {});
      });
    },
    loginAppClick: function () {
      var that = this;
      this.$jsbrige.callNative("loginApp", {}, function (data) {
        that.$jsbrige.callNative("nativeToast", data, function () {});
      });
    },
    dialogClick: function () {
      var that = this;
      that.$jsbrige.callNative(
        "nativeDialog",
        {
          title: "native弹框 标题",
          content: "native弹框 正文螺丝孔没得法凉快圣诞节了农家乐",
        },
        function (data) {
          that.$jsbrige.callNative("nativeToast", data, function () {});
        }
      );
    },
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
